using System;
using System.Collections.Generic;
using System.Text;

namespace TaskMaster
{
    /// <summary>
    /// Represents a task.
    /// </summary>
    public partial class Activity
    {
        public delegate void TaskSelectedHandler();
        //public delegate void TaskSelectedHandler(object obj, TaskSelectedArgs args);
        //public event TaskSelectedHandler TaskSelectedEvent;

        //string name;
        //string description = String.Empty;
        //TimeSpan estimatedTime = TimeSpan.Zero;
        //TimeSpan actualTime = TimeSpan.Zero;
        //Guid _taskID = Guid.NewGuid();
        public TaskSelectedHandler SelectTask;
        //List<string> _tags = new List<string>();


        #region Constructors
        //public Task()
        //{
        //}

        ///// <summary>
        ///// Initializes a new instance of the <c>Task</c> class with the specified name.
        ///// </summary>
        ///// <param name="taskName">A short, descriptive name of the task.</param>
        //public Task(string taskName)
        //{
        //    this.name = taskName;
        //}

        ///// <summary>
        ///// Initializes a new instance of the <c>Task</c> class with the specified name and description.
        ///// </summary>
        ///// <param name="taskName">A short, descriptive name of the task.</param>
        ///// <param name="taskDescription">A more verbose description of the task.</param>
        //public Task(string taskName, string taskDescription)
        //{
        //    this.name = taskName;
        //    this.description = taskDescription;
        //}

        ///// <summary>
        ///// Initializes a new instance of the <c>Task</c> class with the specified GUID.
        ///// </summary>
        ///// <param name="guid">GUID associated with task.</param>
        //public Task(Guid guid)
        //{
        //    _taskID = guid;
        //}
        #endregion

        #region Methods
        /// <summary>
        /// Create a new time record for the task.
        /// </summary>
        /// <returns>A blank time record for the task.</returns>
        public ActivityRecord NewRecord()
        {
            ActivityRecord timeRecord = new ActivityRecord();
            this.ActivityRecord.Add(timeRecord);
            //TimeRecord timeRecord = new TimeRecord(this);

            //Inform the task when the time record against it has been completed so that the duration can be updated.
            timeRecord.RecordCompleteEvent += new ActivityRecord.RecordCompleteHandler(timeRecord_RecordComplete);
            timeRecord.DurationModifiedEvent += new ActivityRecord.DurationModifiedHandler(timeRecord_DurationModifiedEvent);
            return timeRecord;
        }

        /// <summary>
        /// Handles the <c>RecordCompleteEvent</c> event for an owned time record.  Updates the actual time spent on the task based on the completed record.
        /// </summary>
        /// <param name="record">The <c>TimeRecord</c> firing the event.</param>
        private void timeRecord_RecordComplete(ActivityRecord record)
        {
            ActualDuration_Seconds += record.TaskDuration();
        }
        private void timeRecord_DurationModifiedEvent(ActivityRecord record, ActivityRecord.DurationModifiedEventArgs args)
        {
            ActualDuration_Seconds += args.DurationDifference;
        }
        #endregion

        #region Properties
        ///// <summary>
        ///// A short, descriptive name of the task.
        ///// </summary>
        //public string TaskName
        //{
        //    get { return this.name; }
        //    set { this.name = value; }
        //}
        ///// <summary>
        ///// A more verbose description of the task.
        ///// </summary>
        //public string TaskDescription
        //{
        //    get { return this.description; }
        //    set { this.description = value; }
        //}
        ///// <summary>
        ///// Estimated time to complete task.
        ///// </summary>
        ///// <exception>Exception thrown on attempt to set <c>EstimatedTime</c> to a negative value.</exception>
        //public TimeSpan EstimatedTime
        //{
        //    get { return estimatedTime; }
        //    set
        //    {
        //        if (value >= TimeSpan.Zero) { estimatedTime = value; }
        //        else { throw new Exception("EstimatedTime must be a non-negative time span."); }
        //    }
        //}
        ///// <summary>
        ///// Actual time that has been spent on a task to date.
        ///// </summary>
        //public TimeSpan ActualTime
        //{
        //    get { return actualTime; }
        //}
        ///// <summary>
        ///// GUID corresponding to task.
        ///// </summary>
        //public Guid TaskID
        //{
        //    get { return _taskID; }
        //}

        //public List<String> Tags
        //{
        //    get { return _tags; }
        //}

        #endregion


        //public class TaskSelectedArgs : EventArgs
        //{          
        //}
    }
}
